﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JR.Trc.MessageCenter.Lib.Impls
{
    public class RbMqMessageConsumer : IMessageConsumer
    {
        private RbmqParameters paras = null;
        public RbMqMessageConsumer(RbmqParameters paras)
        {
            this.paras = paras;
        }
        public void ConsumeMsg()
        {
            if (string.IsNullOrWhiteSpace(this.paras.ExchangeName))
            {
                throw new ArgumentNullException(string.Format("参数{0}无效!", nameof(this.paras.ExchangeName)));
            }
            if (string.IsNullOrWhiteSpace(this.paras.ExchangeType))
            {
                throw new ArgumentNullException(string.Format("参数{0}无效!", nameof(this.paras.ExchangeType)));
            }
            if (string.IsNullOrWhiteSpace(this.paras.RoutingKey))
            {
                throw new ArgumentNullException(string.Format("参数{0}无效!", nameof(this.paras.RoutingKey)));
            }
            if (string.IsNullOrWhiteSpace(this.paras.QueueName))
            {
                throw new ArgumentNullException(string.Format("参数{0}无效!", nameof(this.paras.QueueName)));
            }
            RabbitMQHelper.Consume(this.paras.ExchangeName, ExchangeType.Direct, this.paras.RoutingKey, this.paras.QueueName, this.paras.CousumeFun, this.paras.BeginAction);
        }
    }
}
